cap log close

global path = "****"

local name= "acr_weights_by_arm"  
local date = "060220"
global logname = "$path/`name'_`date'.log"

clear
set more off
cd "$path"
log using "$logname", replace

use "$path/Data/penalty_sample.dta", clear

*variables for months of extra coverage

forval m=1/24 {
	cap drop months_`m'_or_more
	gen months_`m'_or_more = covered1718 >=`m'
}

*sample restriction
keep if age_2017<65 & age_2017>=45
keep if notall16 == 1


*iv
estimates clear
eststo clear

cap erase "$path/acr_by_arm_`date'.ster"

local arm early nonpersonalize exemption_info base

foreach i of varlist `arm'{
ivregress 2sls dead1718 (covered1718=treatment) if treatment == 0 | `i' == 1, cl(tin)
eststo
estadd scalar nobs e(N)
summ `e(depvar)' if e(sample)&treatment==0
estadd scalar ymean=r(mean)*100
estimates save "$path/acr_by_arm_`date'.ster", append
}



*extra months
foreach i of varlist `arm'{

estimates clear
eststo clear

cap erase "$path/`i'_months_`date'.ster"

forval m=1/24 {
	reg months_`m'_or_more treatment if treatment == 0 | `i' == 1, cl(tin)
	eststo
	estadd scalar nobs e(N)
	summ `e(depvar)' if e(sample)&treatment==0
	estadd scalar ymean=r(mean)*100
	estimates save "$path/`i'_months_`date'.ster", append
}
}

log close

